package reflect;

import reflect.annotations.AutoRunMethod;

import java.lang.reflect.Method;

/**
 * 访问方法上的注解
 */
public class ReflectDemo10 {
    public static void main(String[] args) throws Exception {
        Class cls = Class.forName("reflect.Person");
        Object obj = cls.newInstance();

        Method[] methods = cls.getDeclaredMethods();
        for(Method method : methods) {
            if (method.isAnnotationPresent(AutoRunMethod.class)) {
                System.out.println("调用方法:"+method.getName()+"()");
                method.invoke(obj);
            }
        }
    }
}



